                .586
                TITLE   CODEC__NO_MMX
                .MODEL  FLAT, STDCALL


INTEL_PutDelta_BaseX__NO_MMX			PROTO	C, Dest:DWORD, Top:DWORD, Center:DWORD, Bottom:DWORD, W:DWORD, \
								Quant:DWORD, Rest_Delta:DWORD, Prob:DWORD, Delta:DWORD, NewIndex_X:DWORD

INTEL_PutDelta_BaseX_MinProb__NO_MMX	PROTO	C, Dest:DWORD, Top:DWORD, Center:DWORD, Bottom:DWORD, W:DWORD, \
								Quant:DWORD, Rest_Delta:DWORD, Prob:DWORD, Delta:DWORD, MinProb:DWORD, \
								Delta_Pnt:DWORD, NewIndex_X:DWORD



INTEL_PutDelta_BaseY__NO_MMX			PROTO	C, Dest:DWORD, Sorc:DWORD, Top:DWORD, Bottom:DWORD, W:DWORD, \
								Quant:DWORD, Rest_Delta:DWORD, Prob:DWORD, Delta:DWORD, NewIndex_Y:DWORD

INTEL_PutDelta_BaseY_MinProb__NO_MMX	PROTO	C, Dest:DWORD, Sorc:DWORD, Top:DWORD, Bottom:DWORD, W:DWORD, \
								Quant:DWORD, Rest_Delta:DWORD, Prob:DWORD, Delta:DWORD, MinProb:DWORD, \
								Delta_Pnt:DWORD, NewIndex_Y:DWORD




INTEL_SetProb_BaseX__NO_MMX				PROTO	C, Dest:DWORD, Top:DWORD, Center:DWORD, Bottom:DWORD, W:DWORD, \
								Prob:DWORD, NewIndex_X:DWORD

INTEL_SetProb_BaseX_MinProb__NO_MMX		PROTO	C, Dest:DWORD, Top:DWORD, Center:DWORD, Bottom:DWORD, W:DWORD, \
								Prob:DWORD, ProbLocation:DWORD, MinProb:DWORD, Delta_Pnt:DWORD, Prob_Pnt:DWORD, \
								NewIndex_X:DWORD





INTEL_SetProb_BaseY__NO_MMX				PROTO	C, Top:DWORD, Bottom:DWORD, W:DWORD, Prob:DWORD, NewIndex_Y:DWORD

INTEL_SetProb_BaseY_MinProb__NO_MMX		PROTO	C, Top:DWORD, Bottom:DWORD, W:DWORD, \
								Prob:DWORD, ProbLocation:DWORD, MinProb:DWORD, Delta_Pnt:DWORD, Prob_Pnt:DWORD, \
								NewIndex_Y:DWORD



INTEL_Aver_Line__NO_MMX					PROTO	C, Dest:DWORD, Top:DWORD, Bottom:DWORD, W:DWORD


;====================================================================
;				                                                    
;				M A C R O																
;																	
;====================================================================

;--------------------------------------------------------------------
;				                                                    
;				Probability																
;
; BB = Base1+Base2;
; Pr= abs(Base1 - Base2) * 8 + abs(BB - N1 * 2) + abs(BB - N2 * 2) + abs(BB - N3 * 2) + abs(BB - N4 * 2);
;
; input:	EAX		N1 N2 N3 N4
;			EBX		Base1 Base2
;
; output: 	EDX     Base1+Base2
;			EBX		Probability															
;--------------------------------------------------------------------
Calc_Probability	MACRO
LOCAL	L1, L2, L3, L4, L5			
		MOVZX	ECX,BL
		SHR		EBX,8
		LEA		EDX,[EBX+ECX]		;; BB

		SUB		EBX,ECX				;; Base1 - Base2
		JGE		L1				
		NEG		EBX  
L1:		SHL		EBX,3

		MOVZX	ECX,AL
		SHL		ECX,1
		SUB		ECX,EDX
		JGE		L2			
		NEG		ECX
L2:		ADD		EBX,ECX

		MOVZX	ECX,AH
		SHL		ECX,1
		SHR		EAX,16
		SUB		ECX,EDX
		JGE		L3			
		NEG		ECX
L3:		ADD		EBX,ECX
		
		MOVZX	ECX,AL
		SHL		ECX,1
		SUB		ECX,EDX
		JGE		L4			
		NEG		ECX
L4:		ADD		EBX,ECX

		MOVZX	ECX,AH
		SHL		ECX,1
		SUB		ECX,EDX
		JGE		L5			
		NEG		ECX
L5:		ADD		EBX,ECX
			
ENDM



;--------------------------------------------------------------------
;				                                                    
;				PutDelta																
; input:	EAX		N1 N2 N3 N4
;			EBX		Base1 Base2
;			EDI		dest
;			[EDI]	V															
;			ESI		*Delta_Pnt
;--------------------------------------------------------------------
PutDelta	MACRO	_MinProb_
LOCAL	L1, L2
		
		Calc_Probability					;; EBX=Probability / EDX=BB
		INC		EDX
		SHR		EDX,1						;; BB=(BB+1)>>1

IFNB	<_MinProb_>		
		CMP		EBX,[MinProb]
		JL		L1
ENDIF
		
		MOV		EAX,[Probability]
		MOV		ECX,[NewIndex]
		MOV		WORD PTR [EAX+ESI*2],BX		;; Probability[*Delta_Pnt]= Pr	
		INC		DWORD PTR [ECX+EBX*4]		;; NewIndex[Pr] += 1

		MOVZX	EAX,BYTE PTR [EDI]			;; V
		MOV		EBX,[Quant]
		SUB		EAX,EDX						;; V -= BB
		MOV		BX,WORD PTR [EBX+EAX*2]		;; Quant[V]
		MOV		ECX,[Rest_Delta]
		MOVSX	ECX,WORD PTR [ECX+EAX*2]	;; Rest_Delta[V]
		
		MOV		EAX,[QuantDelta]
		MOV		[EAX+ESI],BL				;; QuantDelta[*Delta_Pnt] = Quant[V]
		INC		ESI							;; *Delta_Pnt += 1

		;; CLIP:
		ADD		EDX,ECX
		JL		L2
		CMP		EDX,255
		JLE		L1
		MOV		EDX,255
		JMP		L1
L2:		MOV		EDX,0
			
L1:		MOV		[EDI],DL
		INC		EDI
			

ENDM		


;--------------------------------------------------------------------
;				                                                    
;				SetProb																
;																	
;--------------------------------------------------------------------
SetProb	MACRO	_MinProb_, _X_
LOCAL	L1
		
		Calc_Probability					;; EBX=Probability / EDX=BB
		
IFNB	<_X_>		
		INC		EDX
		SHR		EDX,1						;; BB=(BB+1)>>1
		MOV		[EDI],DL					;; *dest =(BB+1)>>1
		INC		EDI
ENDIF

IFNB	<_MinProb_>		
		CMP		EBX,[MinProb]
		JL		L1
ENDIF
		
		MOV		EAX,[Probability]
		MOV		ECX,[NewIndex]
		MOV		WORD PTR [EAX+ESI*2],BX		;; Probability[*Delta_Pnt]= Pr	
		INC		DWORD PTR [ECX+EBX*4]		;; NewIndex[Pr] += 1

IFNB	<_MinProb_>		
		MOV		ECX,[Prob_Pnt]
		MOV		EAX,[ProbLocation]
		MOV		[EAX+ESI*4],ECX				;; ProbLocation[*Delta_Pnt] = Prob_Pnt
ENDIF

		INC		ESI							;; *Delta_Pnt += 1

			
L1:		
IFNB	<_MinProb_>		
		INC		[Prob_Pnt]
ENDIF
			
	
ENDM		


;--------------------------------------------------------------------
;				                                                    
;				Yput_GetParam																
;																	
;--------------------------------------------------------------------
Yput_GetParam	MACRO	Left, Right			
		MOV		ECX,[Top]
		MOV		EDX,[Bottom]
		INC		[Top]
		INC		[Bottom]
		MOVZX	EBX,BYTE PTR [ECX]
		MOV		AL,[ECX+Left]
		MOV		AH,[EDX+Left]
		MOV		BH,[EDX]
		SHL		EAX,16		
		MOV		AL,[ECX+Right]
		MOV		AH,[EDX+Right]

		MOV		EDX,[Sorc]
		ADD		[Sorc],2
		MOV		CL,[EDX]
		MOV		[EDI],CL
ENDM


;--------------------------------------------------------------------
;				                                                    
;				Yset_GetParam																
;																	
;--------------------------------------------------------------------
Yset_GetParam	MACRO	Left, Right			
		MOV		ECX,[Top]
		MOV		EDX,[Bottom]
		INC		[Top]
		INC		[Bottom]
		MOVZX	EBX,BYTE PTR [ECX]
		MOV		AL,[ECX+Left]
		MOV		AH,[EDX+Left]
		MOV		BH,[EDX]
		SHL		EAX,16		
		MOV		AL,[ECX+Right]
		MOV		AH,[EDX+Right]

ENDM



;====================================================================
;
;				D A T A
;
;====================================================================
				.DATA
				ALIGN	8



;====================================================================
;
;				C O D E
;
;====================================================================
				.CODE
;___________________________________________________________________________________________________________________________
;
;				INTEL_PutDelta_BaseX
;___________________________________________________________________________________________________________________________
INTEL_PutDelta_BaseX__NO_MMX	PROC	C, Dest:DWORD, Top:DWORD, Center:DWORD, Bottom:DWORD, W:DWORD, \
								Quant:DWORD, Rest_Delta:DWORD, Probability:DWORD, QuantDelta:DWORD, \
								NewIndex:DWORD
		PUSHAD

		MOV		ESI,0							; *Delta_Pnt
		MOV		EDI,[Dest]
		
		CMP		[W],2
		JLE		@@10
		
@@5:	MOV		ECX,[Top]
		INC		[Top]
		MOV		AX,WORD PTR [ECX]
		MOV		ECX,[Bottom]
		SHL		EAX,16
		INC		[Bottom]
		MOV		AX,WORD PTR [ECX]				; N1 N2 N3 N4
		
		MOV		ECX,[Center]
		INC		[Center]
		MOVZX	EBX,WORD PTR [ECX]
		MOV		[EDI],BL
		INC		EDI

		PutDelta	
		SUB		[W],2
		CMP		[W],2
		JG		@@5		
								
@@10:	
		MOV		ECX,[Center]
		MOVZX	EBX,BYTE PTR [ECX]
		MOV		[EDI],BL
		INC		EDI

		CMP		[W],1
		JE		@@100

		MOV		BH,BL

		MOV		ECX,[Top]
		MOV		AL,[ECX]
		MOV		AH,AL
		MOV		ECX,[Bottom]
		SHL		EAX,16
		MOV		AL,[ECX]
		MOV		AH,AL
						
		PutDelta	
		


@@100:	POPAD

		RET		

INTEL_PutDelta_BaseX__NO_MMX	ENDP

;___________________________________________________________________________________________________________________________
;
;				INTEL_SetProb_BaseX
;___________________________________________________________________________________________________________________________
INTEL_SetProb_BaseX__NO_MMX	PROC	C, Dest:DWORD, Top:DWORD, Center:DWORD, Bottom:DWORD, W:DWORD, \
							Probability:DWORD, NewIndex:DWORD

		PUSHAD



		MOV		ESI,0							; *Delta_Pnt
		MOV		EDI,[Dest]
		
		CMP		[W],2
		JLE		@@10
		
@@5:	MOV		ECX,[Top]
		INC		[Top]
		MOV		AX,WORD PTR [ECX]
		MOV		ECX,[Bottom]
		SHL		EAX,16
		INC		[Bottom]
		MOV		AX,WORD PTR [ECX]				; N1 N2 N3 N4
		
		MOV		ECX,[Center]
		INC		[Center]
		MOVZX	EBX,WORD PTR [ECX]
		MOV		[EDI],BL
		INC		EDI

		SetProb	, _X_	
		SUB		[W],2
		CMP		[W],2
		JG		@@5		
								
@@10:	
		MOV		ECX,[Center]
		MOVZX	EBX,BYTE PTR [ECX]
		MOV		[EDI],BL
		INC		EDI

		CMP		[W],1
		JE		@@100

		MOV		BH,BL

		MOV		ECX,[Top]
		MOV		AL,[ECX]
		MOV		AH,AL
		MOV		ECX,[Bottom]
		SHL		EAX,16
		MOV		AL,[ECX]
		MOV		AH,AL
						
		SetProb	, _X_	

@@100:	POPAD

		RET		

INTEL_SetProb_BaseX__NO_MMX	ENDP

;___________________________________________________________________________________________________________________________
;
;				INTEL_PutDelta_BaseX_MinProb
;___________________________________________________________________________________________________________________________
INTEL_PutDelta_BaseX_MinProb__NO_MMX	PROC	C, Dest:DWORD, Top:DWORD, Center:DWORD, Bottom:DWORD, W:DWORD, \
								Quant:DWORD, Rest_Delta:DWORD, Probability:DWORD, QuantDelta:DWORD,    \
								MinProb:DWORD, Delta_Pnt:DWORD, NewIndex:DWORD


		PUSHAD

		MOV		ESI,0							; *Delta_Pnt
		MOV		EDI,[Dest]
		
		CMP		[W],2
		JLE		@@10
		
@@5:	MOV		ECX,[Top]
		INC		[Top]
		MOV		AX,WORD PTR [ECX]
		MOV		ECX,[Bottom]
		SHL		EAX,16
		INC		[Bottom]
		MOV		AX,WORD PTR [ECX]				; N1 N2 N3 N4
		
		MOV		ECX,[Center]
		INC		[Center]
		MOVZX	EBX,WORD PTR [ECX]
		MOV		[EDI],BL
		INC		EDI

		PutDelta	_MinProb_
		SUB		[W],2
		CMP		[W],2
		JG		@@5		
								
@@10:	
		MOV		ECX,[Center]
		MOVZX	EBX,BYTE PTR [ECX]
		MOV		[EDI],BL
		INC		EDI

		CMP		[W],1
		JE		@@100

		MOV		BH,BL

		MOV		ECX,[Top]
		MOV		AL,[ECX]
		MOV		AH,AL
		MOV		ECX,[Bottom]
		SHL		EAX,16
		MOV		AL,[ECX]
		MOV		AH,AL
						
		PutDelta	_MinProb_
		


@@100:	MOV		EAX,[Delta_Pnt]
		ADD		[EAX],ESI

		POPAD

		RET		

INTEL_PutDelta_BaseX_MinProb__NO_MMX	ENDP


;___________________________________________________________________________________________________________________________
;
;				INTEL_SetProb_BaseX_MinProb
;___________________________________________________________________________________________________________________________
INTEL_SetProb_BaseX_MinProb__NO_MMX	PROC	C, Dest:DWORD, Top:DWORD, Center:DWORD, Bottom:DWORD, W:DWORD, \
									Probability:DWORD, ProbLocation:DWORD, MinProb:DWORD, Delta_Pnt:DWORD, \
									Prob_Pnt:DWORD, NewIndex:DWORD

		PUSHAD

		MOV		ESI,0							; *Delta_Pnt
		MOV		EDI,[Dest]
		
		CMP		[W],2
		JLE		@@10
		
@@5:	MOV		ECX,[Top]
		INC		[Top]
		MOV		AX,WORD PTR [ECX]
		MOV		ECX,[Bottom]
		SHL		EAX,16
		INC		[Bottom]
		MOV		AX,WORD PTR [ECX]				; N1 N2 N3 N4
		
		MOV		ECX,[Center]
		INC		[Center]
		MOVZX	EBX,WORD PTR [ECX]
		MOV		[EDI],BL
		INC		EDI

		SetProb	_MinProb_, _X_
		SUB		[W],2
		CMP		[W],2
		JG		@@5		
								
@@10:	
		MOV		ECX,[Center]
		MOVZX	EBX,BYTE PTR [ECX]
		MOV		[EDI],BL
		INC		EDI

		CMP		[W],1
		JE		@@100

		MOV		BH,BL

		MOV		ECX,[Top]
		MOV		AL,[ECX]
		MOV		AH,AL
		MOV		ECX,[Bottom]
		SHL		EAX,16
		MOV		AL,[ECX]
		MOV		AH,AL
						
		SetProb	_MinProb_, _X_
		


@@100:	MOV		EAX,[Delta_Pnt]
		ADD		[EAX],ESI



		POPAD

		RET		

INTEL_SetProb_BaseX_MinProb__NO_MMX	ENDP


;___________________________________________________________________________________________________________________________
;
;				INTEL_PutDelta_BaseY
;___________________________________________________________________________________________________________________________
INTEL_PutDelta_BaseY__NO_MMX	PROC	C, Dest:DWORD, Sorc:DWORD, Top:DWORD, Bottom:DWORD, W:DWORD, \
								Quant:DWORD, Rest_Delta:DWORD, Probability:DWORD, QuantDelta:DWORD, NewIndex:DWORD
		
		PUSHAD

		MOV		EDI,[Dest]
		MOV		ESI,0



		Yput_GetParam	0, 1
		PutDelta
		DEC		[W]

		CMP		[W],1
		JLE		@@10
@@5:		

		Yput_GetParam	-1, 1
		PutDelta
		DEC		[W]
					
		CMP		[W],1
		JG		@@5
			
@@10:	Yput_GetParam	-1, 0
		PutDelta


		POPAD

		RET		

INTEL_PutDelta_BaseY__NO_MMX	ENDP

;___________________________________________________________________________________________________________________________
;
;				INTEL_PutDelta_BaseY_MinProb
;___________________________________________________________________________________________________________________________
INTEL_PutDelta_BaseY_MinProb__NO_MMX	PROC	C, Dest:DWORD, Sorc:DWORD, Top:DWORD, Bottom:DWORD, W:DWORD, \
								Quant:DWORD, Rest_Delta:DWORD, Probability:DWORD, QuantDelta:DWORD, MinProb:DWORD, \
								Delta_Pnt:DWORD, NewIndex:DWORD

		PUSHAD

		MOV		EDI,[Dest]
		MOV		ESI,0



		Yput_GetParam	0, 1
		PutDelta	_MinProb_
		DEC		[W]

		CMP		[W],1
		JLE		@@10
@@5:		

		Yput_GetParam	-1, 1
		PutDelta	_MinProb_
		DEC		[W]
					
		CMP		[W],1
		JG		@@5
			
@@10:	Yput_GetParam	-1, 0
		PutDelta	_MinProb_




		MOV		EAX,[Delta_Pnt]
		ADD		[EAX],ESI

		POPAD

		RET		

INTEL_PutDelta_BaseY_MinProb__NO_MMX	ENDP



;___________________________________________________________________________________________________________________________
;
;				INTEL_SetProb_BaseY
;___________________________________________________________________________________________________________________________
INTEL_SetProb_BaseY__NO_MMX	PROC	C, Top:DWORD, Bottom:DWORD, W:DWORD, Probability:DWORD, NewIndex:DWORD


		PUSHAD

		MOV		ESI,0



		Yset_GetParam	0, 1
		SetProb
		DEC		[W]

		CMP		[W],1
		JLE		@@10
@@5:		

		Yset_GetParam	-1, 1
		SetProb
		DEC		[W]
					
		CMP		[W],1
		JG		@@5
			
@@10:	Yset_GetParam	-1, 0
		SetProb

		POPAD

		RET		

INTEL_SetProb_BaseY__NO_MMX	ENDP


;___________________________________________________________________________________________________________________________
;
;				INTEL_SetProb_BaseY_MinProb
;___________________________________________________________________________________________________________________________
INTEL_SetProb_BaseY_MinProb__NO_MMX	PROC	C, Top:DWORD, Bottom:DWORD, W:DWORD, \
									Probability:DWORD, ProbLocation:DWORD, MinProb:DWORD, Delta_Pnt:DWORD, \
									Prob_Pnt:DWORD, NewIndex:DWORD
		PUSHAD

		MOV		ESI,0



		Yset_GetParam	0, 1
		SetProb	_MinProb_
		DEC		[W]

		CMP		[W],1
		JLE		@@10
@@5:		

		Yset_GetParam	-1, 1
		SetProb	_MinProb_
		DEC		[W]
					
		CMP		[W],1
		JG		@@5
			
@@10:	Yset_GetParam	-1, 0
		SetProb	_MinProb_




		MOV		EAX,[Delta_Pnt]
		ADD		[EAX],ESI



		POPAD

		RET		

INTEL_SetProb_BaseY_MinProb__NO_MMX	ENDP

;___________________________________________________________________________________________________________________________
;
;				INTEL_Aver_Line
;___________________________________________________________________________________________________________________________
INTEL_Aver_Line__NO_MMX	PROC	C, Dest:DWORD, Top:DWORD, Bottom:DWORD, W:DWORD

		PUSHAD

		MOV		EDI,[Dest]
		MOV		ESI,[Top]
		MOV		EDX,[Bottom]
		MOV		ECX,[W]

@@5:	MOVZX	EAX,BYTE PTR [ESI+ECX-1]
		MOVZX	EBX,BYTE PTR [EDX+ECX-1]
		LEA		EAX,BYTE PTR [EAX+EBX+1]
		SHR		EAX,1
		MOV		[EDI+ECX-1],AL		
		LOOP	@@5
		
		POPAD

		RET		

INTEL_Aver_Line__NO_MMX	ENDP


END